# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Baptiste Jonglez <archlinux at bitsofnetworks dot org>
# Contributor: Andy Weidenbaum <archbaum@gmail.com>

pkgname=libsecp256k1
_commit=7fea0055b88a8f1500326978ed1e239fa49256ea # git rev-parse v${pkgver}
pkgver=0.3.2
pkgrel=3
epoch=1
pkgdesc="Optimized C library for EC operations on curve secp256k1"
arch=(loong64 x86_64)
url="https://github.com/bitcoin-core/secp256k1"
license=(MIT)
depends=(glibc)
makedepends=(git)
provides=(libsecp256k1.so)
source=(git+https://github.com/bitcoin-core/secp256k1.git?signed#tag=${_commit})
sha256sums=('SKIP')
validpgpkeys=('09E03F871092E40E106E902B33BC86AB80FF5516' # Tim Ruffing
              '133EAC179436F14A5CF1B794860FEB804E669320' # Pieter Wuille
)

prepare() {
  cd secp256k1
  autoreconf -vfi
}

build() {
  cd secp256k1
  ./configure \
    --prefix=/usr \
    --sbindir=/usr/bin \
    --libexecdir=/usr/bin \
    --sysconfdir=/etc \
    --sharedstatedir=/usr/share/libsecp256k1 \
    --localstatedir=/var/lib/libsecp256k1 \
    --disable-static \
    --disable-benchmark \
    --disable-coverage \
    --enable-module-ecdh \
    --enable-module-recovery \
    --enable-module-extrakeys \
    --enable-module-schnorrsig \
    --enable-tests \
    --enable-exhaustive-tests \
    --with-gnu-ld
  make
}

check() {
  cd secp256k1
  make check
}

package() {
  cd secp256k1
  make DESTDIR="${pkgdir}" install
  install -Dm644 COPYING -t "${pkgdir}"/usr/share/licenses/${pkgname}
}
